home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / UNIX.ZIP / GUESS / GETPWENT.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  1KB  |  65 lines

  1.     /*****************************************************
  2.  
  3.           Fast DES program module
  4.        - Copyright 1991, Christian Beaumont
  5.  
  6.        This program is free software; you can
  7.        redistribute it and/or modify it as you see fit.
  8.  
  9.        This program is distributed in the hope that it
  10.        will be useful, but WITHOUT ANY WARRANTY; without
  11.        even the implied warranty of MERCHANTABILITY or
  12.        FITNESS FOR A PARTICULAR PURPOSE.
  13.  
  14.     *****************************************************/
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "fdes.h"
  19.  
  20. struct passwd *getpwent(char *fn)
  21. {
  22. static FILE *f = NULL;
  23. static struct passwd p;
  24. char s[200];
  25. int l;
  26.  
  27.     if(f == NULL)
  28.         if((f = fopen(fn,"r")) == NULL){
  29.             perror("File error");
  30.             return NULL;
  31.         }
  32.  
  33.     for(;;){
  34.         if(fgets(s,200,f)==NULL){
  35.             fclose(f);
  36.             f = NULL;
  37.             return NULL;
  38.         }
  39.  
  40.         l = strlen(s)-1;
  41.  
  42.         s[l] = '\0';
  43.  
  44.         if(l == 0)
  45.             continue;
  46.  
  47.         p.pw_user[0]    = '\0';
  48.         p.pw_passwd[0]    = '\0';
  49.         p.pw_gecos[0]    = '\0';
  50.         p.pw_dir[0]        = '\0';
  51.         p.pw_shell[0]    = '\0';
  52.  
  53.         strncat(p.pw_user,strtok(s,":"),9);
  54.         strncat(p.pw_passwd,strtok(NULL,":"),13);
  55.         sscanf(strtok(NULL,":"),"%d",&p.pw_uid);
  56.         sscanf(strtok(NULL,":"),"%d",&p.pw_gid);
  57.         strncat(p.pw_gecos,strtok(NULL,":"),39);
  58.         strncat(p.pw_dir,strtok(NULL,":"),39);
  59.         strncat(p.pw_shell,strtok(NULL,":"),20);
  60.         return &p;
  61.     }
  62. }
  63.  
  64.  
  65.